class Group:

    def __init__(self, studnets, group_size, groupx=1):
        """
        :param studnets: 所有学生  9
        :param group_size: 每组人数 4
        :param groupx: 第几组
        """
        self.studnets = studnets
        self.group_size = group_size
        self.groupx = groupx

    def group_count(self):
        if len(self.studnets) % self.group_size:
            return len(self.studnets) // self.group_size + 1
        else:
            return len(self.studnets) // self.group_size

    def has_pregroup(self):
        """
        有没有上一组
        :return:
        """
        # if self.groupx > 1:
        #     return True
        # else:
        #     return False
        return self.groupx > 1

    def has_nextgroup(self):
        """
        判断有没有下一页
        :return:
        """
        return self.groupx < self.group_count()

    def get_groupx(self):
        """
        获取某一组的数据
        :return:
        """

        return self.studnets[(self.groupx - 1) * self.group_size:self.groupx * self.group_size]


# g = Group(range(1, 11), 3, 4)
# print(g.get_groupx())

class MyPaginator:

    def __init__(self, obj_list, page_size):
        """
        :param obj_list: 所有学生  9
        :param page_size: 每组人数 4
        :param groupx: 第几组
        """
        self.studnets = obj_list
        self.group_size = page_size

    def max_page(self):
        if len(self.studnets) % self.group_size:
            return len(self.studnets) // self.group_size + 1
        else:
            return len(self.studnets) // self.group_size

    def has_pregroup(self, x):
        """
        有没有上一组
        :return:
        """

        return x > 1

    def has_nextgroup(self, x):
        """
        判断有没有下一页
        :return:
        """
        return x < self.max_page()

    def get_pagex(self, x):
        """
        获取第x页数据
        :param x:
        :return:
        """
        return self.studnets[(x - 1) * self.group_size:x * self.group_size]

# p = MyPaginator(range(20),4)
# print(p.max_page())
# print(p.get_pagex(2))

